package uvuyv;
import java.awt.*;//引入抽象窗口工具包；
import java.awt.event.*;//
import java.util.Calendar;

import javax.swing.*;//
import javax.swing.border.Border;

import org.omg.CORBA.PUBLIC_MEMBER;
import org.omg.CosNaming.NamingContextExtPackage.AddressHelper;

@SuppressWarnings("serial")
class work11 extends JFrame implements ActionListener{
    JButton jiandao,shitou,bu,clear;
    JPanel panel12,panel11;
    JLabel label;


    public work11() {
        setTitle("石头剪刀布");//窗体标题
        setLocation(250,250);//设置窗体左上顶点坐标
        setSize(350,350);//窗体大小
        JMenuBar mbar=new JMenuBar();//创建菜单栏
        setJMenuBar(mbar);
        JMenu m1=new JMenu("结果显示方式");
        JMenu m2=new JMenu("关于游戏");
        mbar.add(m1);
        mbar.add(m2);
        JMenuItem mil1=new JMenuItem("文本显示");//实现菜单项
        JMenuItem mil2=new JMenuItem("图形显示");
        mil2.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                work13 frame2=new work13();
                frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame2.setVisible(true);
            }
        });


        final JMenuItem mil3=new JMenuItem("结束游戏");
        mil3.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                int t=JOptionPane.showConfirmDialog(mil3, "确定要结束游戏吗？");
                if(t==JOptionPane.YES_OPTION) {
                    System.exit(0);
                }
                else if(t==JOptionPane.NO_OPTION) {
                    System.out.println(" ");
                }
                else {
                    System.out.println();
                }
            }
        });

        m1.add(mil1);
        m1.add(mil2);
        m1.add(mil3);


        panel11=new JPanel();
        panel11.setBackground(Color.yellow);
        shitou=new JButton("石头");
        jiandao=new JButton("剪刀");
        bu=new JButton("布");
        clear=new JButton("清空");
        panel12=new JPanel();
        panel12.setBackground(Color.green);
        label=new JLabel("选择剪刀，石头，布开始游戏");
        shitou.addActionListener(this);//给shitou添加事件监听器；
        bu.addActionListener(this);
        jiandao.addActionListener(this);
        clear.addActionListener(this);

        //把对象放入面板里，将面板放入窗体里
        panel11.add(shitou);
        panel11.add(jiandao);
        panel11.add(bu);
        panel11.add(clear);
        panel12.add(label);

        add(panel11,BorderLayout.NORTH);
        add(panel12,BorderLayout.CENTER);
    }
    //实现ActionListener接口方法
    public void actionPerformed(ActionEvent e) {
        if(e.getSource()==shitou) {
            int i=((int)(Math.random()*10))%3;
            switch(i) {
                case 0:label.setText("你出石头，电脑出石头，平局！");
                    break;
                case 1:label.setText("你出石头，电脑出剪刀，恭喜你赢了！");
                    break;
                case 2:label.setText("你出石头，电脑出布，很遗憾你输了！");
                    break;
            }
        }
        else if(e.getSource()==bu) {
            int i=(int)(Math.random()*10)%3;
            switch(i) {
                case 0:label.setText("你出布，电脑出布，平局！");break;
                case 1:label.setText("你出布，电脑出石头，恭喜你赢了！");break;
                case 2:label.setText("你出布，电脑出剪刀，很遗憾你输了！");break;
            }
        }
        else if(e.getSource()==jiandao) {
            int i=(int)((Math.random()*10))%3;
            switch(i) {
                case 0:label.setText("你出剪刀，电脑出剪刀，平局！");break;
                case 1:label.setText("你出剪刀，电脑出布，恭喜你赢了！");break;
                case 2:label.setText("你出剪刀，电脑出石头，很遗憾你输了！");break;
            }
        }
        else if(e.getSource()==clear) {
            label.setText("选择剪刀，石头，布开始游戏");
        }
    }
}
class work13 extends JFrame implements ActionListener{
    /**
     *
     */
    private static final long serialVersionUID = 1L;
    JButton jiandao,shitou,bu,clear;
    JPanel panel2,panel1;
    JLabel label;
    public work13() {
        ImageIcon a=new ImageIcon("D:\\jiandao.jpg");
        ImageIcon b=new ImageIcon("D:\\shitou.jpg");
        ImageIcon c=new ImageIcon("D:\\bu.jpg");
        a.setImage(a.getImage().getScaledInstance(50, 50, 0));
        b.setImage(b.getImage().getScaledInstance(50, 50, 0));
        c.setImage(c.getImage().getScaledInstance(50, 50, 0));
        setTitle("图像");
        setLocation(250,250);
        setSize(300,300);
        panel1=new JPanel();
        panel1.setBackground(Color.yellow);
        shitou =new JButton();
        shitou.setIcon(b);
        jiandao =new JButton();
        jiandao.setIcon(a);
        bu=new JButton();
        bu.setIcon(c);
        clear=new JButton("清空");
        panel2=new JPanel();
        panel2.setBackground(Color.green);
        label=new JLabel("选择剪刀石头布开始游戏");
        shitou.addActionListener(this);
        bu.addActionListener(this);
        jiandao .addActionListener(this);
        clear.addActionListener(this);
        panel1.add(shitou);
        panel1.add(jiandao);
        panel1.add(bu);
        panel1.add(clear);
        panel2.add(label);
        add(panel1,BorderLayout.NORTH);
        add(panel2,BorderLayout.CENTER);
    }
    public void actionPerformed(ActionEvent e) {
        if(e.getSource()==shitou) {
            int i=((int)(Math.random()*10))%3;
            switch(i) {
                case 0:label.setText("你出石头，电脑出石头，平局！");
                    break;
                case 1:label.setText("你出石头，电脑出剪刀，恭喜你赢了！");
                    break;
                case 2:label.setText("你出石头，电脑出布，很遗憾你输了！");
                    break;
            }
        }
        else if(e.getSource()==bu) {
            int i=(int)(Math.random()*10)%3;
            switch(i) {
                case 0:label.setText("你出布，电脑出布，平局！");break;
                case 1:label.setText("你出布，电脑出石头，恭喜你赢了！");break;
                case 2:label.setText("你出布，电脑出剪刀，很遗憾你输了！");break;
            }
        }
        else if(e.getSource()==jiandao) {
            int i=(int)((Math.random()*10))%3;
            switch(i) {
                case 0:label.setText("你出剪刀，电脑出剪刀，平局！");break;
                case 1:label.setText("你出剪刀，电脑出布，恭喜你赢了！");break;
                case 2:label.setText("你出剪刀，电脑出石头，很遗憾你输了！");break;
            }
        }
        else if(e.getSource()==clear) {
            label.setText("选择剪刀，石头，布开始游戏");
        }
    }
}
public  class iojhi {
    public static void main(String[] args) {
        work11 frame=new work11();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
}